package com.cskaoyan.controller.vx;

import com.cskaoyan.bean.MarketComment;
import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.MarketOrderGoods;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.common.OrderPageInfo;
import com.cskaoyan.bean.order.OrderDetail;
import com.cskaoyan.bean.order.WxComment;
import com.cskaoyan.service.CommentService;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName:WXOrderController
 * @Description:TODO
 * @author:leiwenjie
 * @date:2022/9/11 11:19
 * @version:1.0
 */
@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    OrderService orderService;

    @Autowired
    CommentService commentService;

    @RequestMapping("list")
    public BaseRespVo list(OrderPageInfo info) {
        CommonData<MarketOrder> data = orderService.wxQuery(info);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        OrderDetail data = orderService.wxDetail(orderId);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("refund")
    public BaseRespVo refund(Integer orderId) {

        orderService.wxRefund(orderId);
        return BaseRespVo.ok(null);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(Integer orderId) {
        orderService.wxDelete(orderId);
        return BaseRespVo.ok(null);
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map<String, Integer> map) {
        Integer orderId = map.get("orderId");
        orderService.wxConfirm(orderId);
        return BaseRespVo.ok(null);
    }


    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId, Integer goodsId) {
        MarketOrderGoods marketOrderGoods = orderService.goods(orderId, goodsId);
        return BaseRespVo.ok(marketOrderGoods);
    }

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody WxComment comment) {
        orderService.insertOrderComment(comment);
        return BaseRespVo.ok(null);
    }


    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map<String, Integer> map) {
        Integer orderId = map.get("orderId");
        orderService.wxCancel(orderId);
        return BaseRespVo.ok(null);
    }

}
